package com.riko.comic.core.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 登录拦截器
 *
 * @author riko
 * @since 2021/10/29
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        Integer id = (Integer)request.getSession().getAttribute("loginUserId");

        if (id != null) {
            return true;
        } else {
            response.sendRedirect("/sys/user/login");
        }

        return false;
    }

}
